# 导入系统资源模块
import random

from ascript.android.system import R
# 导入动作模块
from ascript.android import action
# 导入节点检索模块
from ascript.android import node
# 导入图色检索模块
from ascript.android import screen

# #导包启动app的包
from airscript.intent import Intent
from ascript.android.node import Selector
from ascript.android import action
# 获取屏幕信息
from ascript.android.system import Device

from .comm.eact import eatBuTie
from .comm.fanka import fanKaLingqu
from .comm.kanju import kanJuLingqu
from .comm.kaixiang import kaiXiangJinBi
from .comm.utils import timeSleep, clickFuLI, clickGuangGao, closeAdvertisingOnce

print("Hello AS!")

# 根据包名启动,推荐使用
# 抖音包
# Intent.run("com.ss.android.ugc.aweme")
Intent.run("com.phoenix.read")
print('启动成功')

# 点击福利
clickFuLI(5)

# 检测签到
# clickQianDao(5)

# # 福利页面点击签到
# clickToQianDao(5)
while True:
    timeSleep()
    element = Selector().path("/FrameLayout/FrameLayout/LynxFlattenUI").find_all()
    if element == None:
        continue
    if len(element)>=250:
        timeSleep()
        # 判断是否存在开箱得金币
        kaixiangjinbi = False
        # 判断是否存在翻卡
        fanka = False
        # 判断是否存在吃饭补贴
        eact = False
        # 判断是否存在签到
        qiandao = False
        # 去看剧
        kanju = False
        for itm in element:
            # print(itm,itm.text, '坐标', itm.center_x, itm.center_y)
            center_x = itm.center_x
            center_y = itm.center_y
            if itm.text=='去签到':
                qiandao = True
                # print(itm.text,'坐标',itm.center_x,itm.center_y)
                # action.click(x=itm.center_x, y=itm.center_y, dur=random.randint(20, 500))
            if ('立即领取' in itm.text or '去领取' in itm.text) and itm.path == '/FrameLayout/FrameLayout/LynxFlattenUI':
                eact = True
            if '立即翻卡' in itm.text:
                fanka = True
            # 去看剧
            if itm.text == '去看剧' and itm.path == '/FrameLayout/FrameLayout/LynxFlattenUI':
                kanju=True
            # 开宝箱得金币
            if itm.text == '开宝箱得金币' and itm.path == '/FrameLayout/FrameLayout/LynxFlattenUI':
                kaixiangjinbi = True
                # print('进入开宝箱得金币')
                # kaiXiangJinBi(itm)
        if qiandao == True:
            print('进入签到')
        if fanka == True:
            print('进入翻卡')
            fanKaLingqu()
        if eact == True:
            print('进入吃饭补贴')
            eatBuTie()
        # if kanju==True:
        #     kanJuLingqu()
        # print(qiandao,fanka,eact,kanju)
        # # 点击广告
        # print('主页=================点击广告')
        # clickGuangGao()
        # # 关闭广告
        # print('主页=================点击关闭广告')
        # closeAdvertisingOnce()
        timeSleep()



